77 static constexpr float defaultGainTick = 690./640.;
95 APV->isMasked = SiStripQuality_->
IsApvBad(APV->DetId,APV->APVId);
98 float newPreviousGain = gainHandle->
getApvGain(APV->APVId,gainHandle->
getRange(APV->DetId, 1),1);
99 if(APV->PreviousGain!=1 and newPreviousGain!=APV->PreviousGain)
edm::LogWarning(
"SiStripGainPCLHarvester")<<
"WARNING: ParticleGain in the global tag changed\n";
100 APV->PreviousGain = newPreviousGain;
102 float newPreviousGainTick = APV->isMasked ? defaultGainTick : gainHandle->
getApvGain(APV->APVId,gainHandle->
getRange(APV->DetId, 0),0);
103 if(APV->PreviousGainTick!=1 and newPreviousGainTick!=APV->PreviousGainTick){
104 edm::LogWarning(
"SiStripGainPCLHarvester")<<
"WARNING: TickMarkGain in the global tag changed\n"<< std::endl
105 <<
" APV->SubDet: "<< APV->SubDet <<
" APV->APVId:" << APV->APVId << std::endl
106 <<
" APV->PreviousGainTick: "<<APV->PreviousGainTick<<
" newPreviousGainTick: "<<newPreviousGainTick<<std::endl;
108 APV->PreviousGainTick = newPreviousGainTick;
115 edm::LogInfo(
"SiStripGainsPCLHarvester") <<
"Starting harvesting statistics" << std::endl;
120 if(!stag.empty() && stag[0]!=
'_') stag.insert(0,1,
'_');
126 if (Charge_Vs_Index==
nullptr) {
127 edm::LogError(
"SiStripGainsPCLHarvester") <<
"Harvesting: could not retrieve " << cvi.c_str()
128 <<
", statistics will not be summed!" << std::endl;
130 edm::LogInfo(
"SiStripGainsPCLHarvester") <<
"Harvesting " 131 << (Charge_Vs_Index)->getTH2S()->GetEntries() <<
" more clusters" << std::endl;
135 std::unique_ptr<SiStripApvGain> theAPVGains = this->
getNewObject(Charge_Vs_Index);
144 throw std::runtime_error(
"PoolDBService required.");
146 edm::LogInfo(
"SiStripGainsPCLHarvester") <<
"Will not produce payload!" << std::endl;
161 std::vector<APVGain::APVmon> new_charge_histos;
163 for (
unsigned int i=0;
i<cnames.size();
i++){
175 MonitorElement* MPV_Vs_EtaTIB = ibooker_.
book2DD(
"MPVvsEtaTIB" ,
"MPV vs Eta TIB" ,50,-3.0,3.0,MPVbin,MPVmin,MPVmax);
176 MonitorElement* MPV_Vs_EtaTID = ibooker_.
book2DD(
"MPVvsEtaTID" ,
"MPV vs Eta TID" ,50,-3.0,3.0,MPVbin,MPVmin,MPVmax);
177 MonitorElement* MPV_Vs_EtaTOB = ibooker_.
book2DD(
"MPVvsEtaTOB" ,
"MPV vs Eta TOB" ,50,-3.0,3.0,MPVbin,MPVmin,MPVmax);
178 MonitorElement* MPV_Vs_EtaTEC = ibooker_.
book2DD(
"MPVvsEtaTEC" ,
"MPV vs Eta TEC" ,50,-3.0,3.0,MPVbin,MPVmin,MPVmax);
179 MonitorElement* MPV_Vs_EtaTECthin = ibooker_.
book2DD(
"MPVvsEtaTEC1",
"MPV vs Eta TEC-thin" ,50,-3.0,3.0,MPVbin,MPVmin,MPVmax);
180 MonitorElement* MPV_Vs_EtaTECthick = ibooker_.
book2DD(
"MPVvsEtaTEC2",
"MPV vs Eta TEC-thick",50,-3.0,3.0,MPVbin,MPVmin,MPVmax);
182 MonitorElement* MPV_Vs_PhiTIB = ibooker_.
book2DD(
"MPVvsPhiTIB" ,
"MPV vs Phi TIB" ,50,-3.4,3.4,MPVbin,MPVmin,MPVmax);
183 MonitorElement* MPV_Vs_PhiTID = ibooker_.
book2DD(
"MPVvsPhiTID" ,
"MPV vs Phi TID" ,50,-3.4,3.4,MPVbin,MPVmin,MPVmax);
184 MonitorElement* MPV_Vs_PhiTOB = ibooker_.
book2DD(
"MPVvsPhiTOB" ,
"MPV vs Phi TOB" ,50,-3.4,3.4,MPVbin,MPVmin,MPVmax);
185 MonitorElement* MPV_Vs_PhiTEC = ibooker_.
book2DD(
"MPVvsPhiTEC" ,
"MPV vs Phi TEC" ,50,-3.4,3.4,MPVbin,MPVmin,MPVmax);
186 MonitorElement* MPV_Vs_PhiTECthin = ibooker_.
book2DD(
"MPVvsPhiTEC1",
"MPV vs Phi TEC-thin ",50,-3.4,3.4,MPVbin,MPVmin,MPVmax);
187 MonitorElement* MPV_Vs_PhiTECthick = ibooker_.
book2DD(
"MPVvsPhiTEC2",
"MPV vs Phi TEC-thick",50,-3.4,3.4,MPVbin,MPVmin,MPVmax);
189 MonitorElement* NoMPVfit = ibooker_.
book2DD(
"NoMPVfit" ,
"Modules with bad Landau Fit",350, -350, 350, 240, 0, 120);
190 MonitorElement* NoMPVmasked = ibooker_.
book2DD(
"NoMPVmasked" ,
"Masked Modules" ,350, -350, 350, 240, 0, 120);
212 MonitorElement* MPVErrorVsMPV = ibooker_.
book2DD(
"MPVErrorVsMPV" ,
"MPV Error vs MPV" , 300, 0, 600, 150, 0, 150);
213 MonitorElement* MPVErrorVsEta = ibooker_.
book2DD(
"MPVErrorVsEta" ,
"MPV Error vs Eta" , 50, -3.0, 3.0, 150, 0, 150);
214 MonitorElement* MPVErrorVsPhi = ibooker_.
book2DD(
"MPVErrorVsPhi" ,
"MPV Error vs Phi" , 50, -3.4, 3.4, 150, 0, 150);
215 MonitorElement* MPVErrorVsN = ibooker_.
book2DD(
"MPVErrorVsN" ,
"MPV Error vs N" , 500, 0, 1000, 150, 0, 150);
217 MonitorElement* DiffWRTPrevGainTIB = ibooker_.
book1DD(
"DiffWRTPrevGainTIB" ,
"Diff w.r.t. PrevGain TIB" , 250, 0,2);
218 MonitorElement* DiffWRTPrevGainTID = ibooker_.
book1DD(
"DiffWRTPrevGainTID" ,
"Diff w.r.t. PrevGain TID" , 250, 0,2);
219 MonitorElement* DiffWRTPrevGainTOB = ibooker_.
book1DD(
"DiffWRTPrevGainTOB" ,
"Diff w.r.t. PrevGain TOB" , 250, 0,2);
220 MonitorElement* DiffWRTPrevGainTEC = ibooker_.
book1DD(
"DiffWRTPrevGainTEC" ,
"Diff w.r.t. PrevGain TEC" , 250, 0,2);
222 MonitorElement* GainVsPrevGainTIB = ibooker_.
book2DD(
"GainVsPrevGainTIB" ,
"Gain vs PrevGain TIB" , 100, 0,2, 100, 0,2);
223 MonitorElement* GainVsPrevGainTID = ibooker_.
book2DD(
"GainVsPrevGainTID" ,
"Gain vs PrevGain TID" , 100, 0,2, 100, 0,2);
224 MonitorElement* GainVsPrevGainTOB = ibooker_.
book2DD(
"GainVsPrevGainTOB" ,
"Gain vs PrevGain TOB" , 100, 0,2, 100, 0,2);
225 MonitorElement* GainVsPrevGainTEC = ibooker_.
book2DD(
"GainVsPrevGainTEC" ,
"Gain vs PrevGain TEC" , 100, 0,2, 100, 0,2);
231 if(APV==
nullptr)
continue;
233 unsigned int Index = APV->Index;
234 unsigned int SubDet = APV->SubDet;
237 float Eta = APV->Eta;
239 float Phi = APV->Phi;
240 float Thickness = APV->Thickness;
241 double FitMPV = APV->FitMPV;
242 double FitMPVErr = APV->FitMPVErr;
243 double Gain = APV->Gain;
244 double NEntries = APV->NEntries;
245 double PreviousGain = APV->PreviousGain;
247 if (SubDet<3)
continue;
251 TH2S *chvsidx = (Charge_Vs_Index)->getTH2S();
252 int bin = chvsidx->GetXaxis()->FindBin(Index);
253 TH1D* Proj = chvsidx->ProjectionY(
"proj",bin,bin);
254 for (
int binId=0; binId<Proj->GetXaxis()->GetNbins();binId++) {
255 double new_charge = Proj->GetXaxis()->GetBinCenter(binId) /
Gain;
256 if (Proj->GetBinContent(binId)!=0.) {
257 for (
unsigned int h=0;
h<charge_histos.size();
h++) {
258 TH1D* chisto = (charge_histos[
h])->getTH1D();
259 for (
int e=0;
e<Proj->GetBinContent(binId);
e++) chisto->Fill(new_charge);
267 if (APV->isMasked) NoMPVmasked->
Fill(z,R);
268 else NoMPVfit->
Fill(z,R);
271 if(FitMPV>0.) Gains->
Fill(Gain);
274 if(Thickness<0.04) MPVs320->
Fill(FitMPV);
275 if(Thickness>0.04) MPVs500->
Fill(FitMPV);
277 MPVError->
Fill(FitMPVErr);
278 MPVErrorVsMPV->
Fill(FitMPV,FitMPVErr);
279 MPVErrorVsEta->
Fill(Eta,FitMPVErr);
280 MPVErrorVsPhi->
Fill(Phi,FitMPVErr);
281 MPVErrorVsN->
Fill(NEntries,FitMPVErr);
284 MPV_Vs_EtaTIB->
Fill(Eta,FitMPV);
285 MPV_Vs_PhiTIB->
Fill(Phi,FitMPV);
286 MPVsTIB->
Fill(FitMPV);
288 }
else if(SubDet==4) {
289 MPV_Vs_EtaTID->
Fill(Eta,FitMPV);
290 MPV_Vs_PhiTID->
Fill(Phi,FitMPV);
291 MPVsTID->
Fill(FitMPV);
292 if(Eta<0.) MPVsTIDM->
Fill(FitMPV);
293 if(Eta>0.) MPVsTIDP->
Fill(FitMPV);
295 }
else if (SubDet==5) {
296 MPV_Vs_EtaTOB->
Fill(Eta,FitMPV);
297 MPV_Vs_PhiTOB->
Fill(Phi,FitMPV);
298 MPVsTOB->
Fill(FitMPV);
300 }
else if (SubDet==6) {
301 MPV_Vs_EtaTEC->
Fill(Eta,FitMPV);
302 MPV_Vs_PhiTEC->
Fill(Phi,FitMPV);
303 MPVsTEC->
Fill(FitMPV);
304 if(Eta<0.) MPVsTECM->
Fill(FitMPV);
305 if(Eta>0.) MPVsTECP->
Fill(FitMPV);
307 MPV_Vs_EtaTECthin->
Fill(Eta,FitMPV);
308 MPV_Vs_PhiTECthin->
Fill(Phi,FitMPV);
309 MPVsTECthin->
Fill(FitMPV);
310 if(Eta>0.) MPVsTECP1->
Fill(FitMPV);
311 if(Eta<0.) MPVsTECM1->
Fill(FitMPV);
314 MPV_Vs_EtaTECthick->
Fill(Eta,FitMPV);
315 MPV_Vs_PhiTECthick->
Fill(Phi,FitMPV);
316 MPVsTECthick->
Fill(FitMPV);
317 if(Eta>0.) MPVsTECP2->
Fill(FitMPV);
318 if(Eta<0.) MPVsTECM2->
Fill(FitMPV);
323 if(SubDet==3 && PreviousGain!=0. ) DiffWRTPrevGainTIB->
Fill(Gain/PreviousGain);
324 else if(SubDet==4 && PreviousGain!=0. ) DiffWRTPrevGainTID->
Fill(Gain/PreviousGain);
325 else if(SubDet==5 && PreviousGain!=0. ) DiffWRTPrevGainTOB->
Fill(Gain/PreviousGain);
326 else if(SubDet==6 && PreviousGain!=0. ) DiffWRTPrevGainTEC->
Fill(Gain/PreviousGain);
328 if(SubDet==3 ) GainVsPrevGainTIB->
Fill(PreviousGain,Gain);
329 else if(SubDet==4 ) GainVsPrevGainTID->
Fill(PreviousGain,Gain);
330 else if(SubDet==5 ) GainVsPrevGainTOB->
Fill(PreviousGain,Gain);
331 else if(SubDet==6 ) GainVsPrevGainTEC->
Fill(PreviousGain,Gain);
342 TH1F* Proj =
nullptr;
343 double FitResults[6];
344 double MPVmean = 300;
346 if ( Charge_Vs_Index==
nullptr ) {
347 edm::LogError(
"SiStripGainsPCLHarvester") <<
"Harvesting: could not execute algoComputeMPVandGain method because " 349 <<
"Please check if input contains " 354 TH2S *chvsidx = (Charge_Vs_Index)->getTH2S();
356 printf(
"Progressing Bar :0%% 20%% 40%% 60%% 80%% 100%%\n");
357 printf(
"Fitting Charge Distribution :");
362 if(I%TreeStep==0){printf(
".");fflush(
stdout);}
363 std::shared_ptr<stAPVGain>
APV = it->second;
364 if(APV->Bin<0) APV->Bin = chvsidx->GetXaxis()->FindBin(APV->Index);
366 if(APV->isMasked){APV->Gain=APV->PreviousGain;
MASKED++;
continue;}
368 Proj = (TH1F*)(chvsidx->ProjectionY(
"",chvsidx->GetXaxis()->FindBin(APV->Index),chvsidx->GetXaxis()->FindBin(APV->Index),
"e"));
373 int SecondAPVId = APV->APVId;
374 if(SecondAPVId%2==0){ SecondAPVId = SecondAPVId+1; }
else{ SecondAPVId = SecondAPVId-1; }
375 std::shared_ptr<stAPVGain> APV2 =
APVsColl[(APV->DetId<<4) | SecondAPVId];
376 if(APV2->Bin<0) APV2->Bin = chvsidx->GetXaxis()->FindBin(APV2->Index);
377 TH1F* Proj2 = (TH1F*)(chvsidx->ProjectionY(
"",APV2->Bin,APV2->Bin,
"e"));
378 if(Proj2){Proj->Add(Proj2,1);
delete Proj2;}
380 for(
unsigned int i=0;
i<16;
i++){
381 auto tmpit =
APVsColl.find((APV->DetId<<4) |
i);
383 std::shared_ptr<stAPVGain> APV2 = tmpit->second;
384 if(APV2->DetId != APV->DetId || APV2->APVId == APV->APVId)
continue;
385 if(APV2->Bin<0) APV2->Bin = chvsidx->GetXaxis()->FindBin(APV2->Index);
386 TH1F* Proj2 = (TH1F*)(chvsidx->ProjectionY(
"",APV2->Bin,APV2->Bin,
"e"));
387 if(Proj2){Proj->Add(Proj2,1);
delete Proj2;}
395 APV->FitMPV = FitResults[0];
396 APV->FitMPVErr = FitResults[1];
397 APV->FitWidth = FitResults[2];
398 APV->FitWidthErr = FitResults[3];
399 APV->FitChi2 = FitResults[4];
400 APV->FitNorm = FitResults[5];
401 APV->NEntries = Proj->GetEntries();
404 APV->Gain = APV->FitMPV / MPVmean;
405 if(APV->SubDet>2)
GOOD++;
407 APV->Gain = APV->PreviousGain;
408 if(APV->SubDet>2)
BAD++;
410 if(APV->Gain<=0) APV->Gain = 1;
420 FitResults[0] = -0.5;
422 FitResults[2] = -0.5;
424 FitResults[4] = -0.5;
430 TF1 MyLandau(
"MyLandau",
"landau",LowRange, HighRange);
431 MyLandau.SetParameter(1,300);
432 InputHisto->Fit(&MyLandau,
"0QR WW");
435 FitResults[0] = MyLandau.GetParameter(1);
436 FitResults[1] = MyLandau.GetParError(1);
437 FitResults[2] = MyLandau.GetParameter(2);
438 FitResults[3] = MyLandau.GetParError(2);
439 FitResults[4] = MyLandau.GetChisquare() / MyLandau.GetNDF();
440 FitResults[5] = MyLandau.GetParameter(0);
447 if(FitResults[0] <= 0 )
return false;
464 auto const &
Det = newBareTkGeomPtr->
dets();
466 unsigned int Index=0;
468 for(
unsigned int i=0;
i<
Det.size();
i++){
477 if(!DetUnit)
continue;
480 unsigned int NAPV = Topo.
nstrips()/128;
482 for(
unsigned int j=0;j<NAPV;j++){
483 auto APV = std::make_shared<stAPVGain>();
492 APV->FitWidthErr = -1;
496 APV->PreviousGain = 1;
497 APV->PreviousGainTick = 1;
498 APV->x = DetUnit->position().basicVector().x();
499 APV->y = DetUnit->position().basicVector().y();
500 APV->z = DetUnit->position().basicVector().z();
501 APV->Eta = DetUnit->position().basicVector().eta();
502 APV->Phi = DetUnit->position().basicVector().phi();
503 APV->R = DetUnit->position().basicVector().transverse();
504 APV->Thickness = DetUnit->surface().bounds().thickness();
506 APV->isMasked =
false;
516 for(
unsigned int i=0;
i<
Det.size();
i++){
521 if(!DetUnit)
continue;
524 unsigned int NROCRow = Topo.
nrows()/(80.);
525 unsigned int NROCCol = Topo.
ncolumns()/(52.);
527 for(
unsigned int j=0;j<NROCRow;j++){
528 for(
unsigned int i=0;
i<NROCCol;
i++){
529 auto APV = std::make_shared<stAPVGain>();
533 APV->APVId = (j<<3 |
i);
538 APV->FitWidthErr = -1;
541 APV->PreviousGain = 1;
542 APV->PreviousGainTick = 1;
543 APV->x = DetUnit->position().basicVector().x();
544 APV->y = DetUnit->position().basicVector().y();
545 APV->z = DetUnit->position().basicVector().z();
546 APV->Eta = DetUnit->position().basicVector().eta();
547 APV->Phi = DetUnit->position().basicVector().phi();
548 APV->R = DetUnit->position().basicVector().transverse();
549 APV->Thickness = DetUnit->surface().bounds().thickness();
550 APV->isMasked =
false;
581 if( Charge_Vs_Index==
nullptr ) {
582 edm::LogError(
"SiStripGainsPCLHarvester") <<
"produceTagFilter -> Return false: could not retrieve the " 584 <<
"Please check if input contains " 590 float integral = (Charge_Vs_Index)->getTH2S()->Integral();
594 <<
"produceTagFilter -> Return false: Statistics is too low : " << integral << std::endl;
600 <<
"produceTagFilter -> Return false: ratio of GOOD/TOTAL is too low: " << (1.0 *
GOOD) / (
GOOD+
BAD) << std::endl;
607 std::unique_ptr<SiStripApvGain>
610 std::unique_ptr<SiStripApvGain>
obj = std::unique_ptr<SiStripApvGain>(
new SiStripApvGain());
613 edm::LogWarning(
"SiStripGainsPCLHarvester")<<
"getNewObject -> will not produce a paylaod because produceTagFilter returned false " << std::endl;
619 std::vector<float> theSiStripVector;
620 unsigned int PreviousDetId = 0;
623 if(APV==
nullptr){ printf(
"Bug\n");
continue; }
624 if(APV->SubDet<=2)
continue;
625 if(APV->DetId != PreviousDetId){
626 if(!theSiStripVector.empty()){
628 if ( !obj->put(PreviousDetId,range) ) printf(
"Bug to put detId = %i\n",PreviousDetId);
630 theSiStripVector.clear();
631 PreviousDetId = APV->DetId;
633 theSiStripVector.push_back(APV->Gain);
635 LogDebug(
"SiStripGainsPCLHarvester")<<
" DetId: "<<APV->DetId
636 <<
" APV: "<<APV->APVId
637 <<
" Gain: "<<APV->Gain
641 if(!theSiStripVector.empty()){
643 if ( !obj->put(PreviousDetId,range) ) printf(
"Bug to put detId = %i\n",PreviousDetId);
std::unique_ptr< SiStripApvGain > getNewObject(const MonitorElement *Charge_Vs_Index)
bool IsApvBad(const uint32_t &detid, const short &apvNb) const
T getUntrackedParameter(std::string const &, T const &) const
virtual int nrows() const =0
edm::ESHandle< TrackerGeometry > tkGeom_
void dqmEndJob(DQMStore::IBooker &ibooker_, DQMStore::IGetter &igetter_) override
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
size_t getNumberOfTags() const
constexpr uint32_t rawId() const
get the raw id
const TrackerTopology * tTopo_
int subdetectorPlane(uint32_t, const TrackerTopology *)
def setup(process, global_tag, zero_tesla=False)
std::vector< std::string > dqm_tag_
void beginRun(edm::Run const &run, edm::EventSetup const &isetup) override
bool produceTagFilter(const MonitorElement *Charge_Vs_Index)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
void getPeakOfLandau(TH1 *InputHisto, double *FitResults, double LowRange=50, double HighRange=5400)
void algoComputeMPVandGain(const MonitorElement *Charge_Vs_Index)
static float getApvGain(const uint16_t &apv, const SiStripApvGain::Range &range)
U second(std::pair< T, U > const &p)
SiStripGainsPCLHarvester(const edm::ParameterSet &ps)
std::vector< MonitorElement * > FetchMonitor(std::vector< APVmon >, uint32_t, const TrackerTopology *topo=0)
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
Data available (reporting)
void addDefault(ParameterSetDescription const &psetDescription)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void setCurrentFolder(std::string const &fullpath)
double tagCondition_GoodFrac
bool doChargeMonitorPerPlane
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
std::pair< ContainerIterator, ContainerIterator > Range
const std::complex< double > I
void writeOne(T *payload, Time_t time, const std::string &recordName, bool withlogging=false)
std::vector< std::string > VChargeHisto
Integral< F, X >::type integral(const F &f)
MonitorElement * get(std::string const &path)
bin
set the eta bin as selection string.
virtual void checkAndRetrieveTopology(const edm::EventSetup &setup)
std::string m_calibrationMode
bool IsGoodLandauFit(double *FitResults)
void gainQualityMonitor(DQMStore::IBooker &ibooker_, const MonitorElement *Charge_Vs_Index) const
virtual int nstrips() const =0
int subdetectorSide(uint32_t, const TrackerTopology *)
const TrackerGeometry * bareTkGeomPtr_
void endRun(edm::Run const &run, edm::EventSetup const &isetup) override
double tagCondition_NClusters
virtual void checkBookAPVColls(const edm::EventSetup &setup)
std::vector< std::shared_ptr< stAPVGain > > APVsCollOrdered
virtual int ncolumns() const =0
cond::Time_t currentTime() const
MonitorElement * book2DD(Args &&...args)
std::vector< std::pair< std::string, std::string > > monHnames(std::vector< std::string >, bool, const char *tag)
MonitorElement * book1DD(Args &&...args)
T const * product() const
int subdetectorId(uint32_t)
constexpr DetId()
Create an empty or null id (also for persistence)
const SiStripApvGain::Range getRange(uint32_t detID) const
std::unordered_map< unsigned int, std::shared_ptr< stAPVGain > > APVsColl