69 #include "TObjString.h"
79 #include <ext/hash_map>
86 using namespace __gnu_cxx;
87 using __gnu_cxx::hash_map;
131 virtual void algoEndJob ()
override;
134 int statCollectionFromMode(
const char*
tag)
const;
135 void bookDQMHistos(
const char* dqm_dir,
const char* tag);
138 void swapBFieldMode(
void);
141 void algoAnalyzeTheTree();
142 void algoComputeMPVandGain();
145 void getPeakOfLandau(TH1* InputHisto,
double* FitResults,
double LowRange=50,
double HighRange=5400);
146 bool IsGoodLandauFit(
double* FitResults);
148 void MakeCalibrationMap();
149 bool produceTagFilter();
226 unsigned int eventnumber =0;
266 template <
class T>
bool operator () (
const T& PseudoDetId1,
const T& PseudoDetId2) {
return PseudoDetId1==PseudoDetId2; }
270 __gnu_cxx::hash_map<unsigned int, stAPVGain*, __gnu_cxx::hash<unsigned int>,
isEqual >
APVsColl;
276 std::vector<string>::const_iterator it=dqm_tag_.begin();
277 while(it!=dqm_tag_.end()) {
278 if(*it==
std::string(tag))
return it-dqm_tag_.begin();
288 if(A->GetNbinsX() == B->GetNbinsX()){
291 for(
int x=0;
x<=B->GetNbinsX()+1;
x++){
292 for(
int y=0;y<=B->GetNbinsY()+1; y++){
293 A->SetBinContent(
x,y,A->GetBinContent(
x,y)+B->GetBinContent(
x,y));
393 EventPrefix_ = evtinfo_pset.getUntrackedParameter<
string>(
"prefix");
394 EventSuffix_ = evtinfo_pset.getUntrackedParameter<
string>(
"suffix");
399 TrackPrefix_ = track_pset.getUntrackedParameter<
string>(
"prefix");
400 TrackSuffix_ = track_pset.getUntrackedParameter<
string>(
"suffix");
413 edm::LogInfo(
"SiStripGainFromCalibTree") <<
"Setting " << dqm_dir <<
"in DQM and booking histograms for tag "
416 dbe->setCurrentFolder(dqm_dir);
419 if(stag.size()!=0 && stag[0]!=
'_') stag.insert(0,1,
'_');
434 Charge_Vs_Index[elepos] =
dbe->book2D(cvi.c_str() , cvi.c_str() , 88625, 0 , 88624,2000,0,4000);
453 const char * dqm_dir =
"AlCaReco/SiStripGainsHarvesting/";
467 auto const &
Det = tkGeom->dets();
471 unsigned int Index=0;
472 for(
unsigned int i=0;
i<
Det.size();
i++){
480 if(!DetUnit)
continue;
483 unsigned int NAPV = Topo.
nstrips()/128;
485 for(
unsigned int j=0;
j<NAPV;
j++){
501 APV->
x = DetUnit->position().basicVector().x();
502 APV->
y = DetUnit->position().basicVector().y();
503 APV->
z = DetUnit->position().basicVector().z();
504 APV->
Eta = DetUnit->position().basicVector().eta();
505 APV->
Phi = DetUnit->position().basicVector().phi();
506 APV->
R = DetUnit->position().basicVector().transverse();
507 APV->
Thickness = DetUnit->surface().bounds().thickness();
519 for(
unsigned int i=0;
i<
Det.size();
i++){
524 if(!DetUnit)
continue;
527 unsigned int NROCRow = Topo.
nrows()/(80.);
528 unsigned int NROCCol = Topo.
ncolumns()/(52.);
530 for(
unsigned int j=0;
j<NROCRow;
j++){
531 for(
unsigned int i=0;
i<NROCCol;
i++){
546 APV->
x = DetUnit->position().basicVector().x();
547 APV->
y = DetUnit->position().basicVector().y();
548 APV->
z = DetUnit->position().basicVector().z();
549 APV->
Eta = DetUnit->position().basicVector().eta();
550 APV->
Phi = DetUnit->position().basicVector().phi();
551 APV->
R = DetUnit->position().basicVector().transverse();
552 APV->
Thickness = DetUnit->surface().bounds().thickness();
582 double average_current = runInfo.
product()->m_avg_current;
586 return ( (isOn && !is0T) || (!isOn && is0T) );
604 edm::LogInfo(
"SiStripGainFromCalibTree") <<
"Switching calibration mode for endorsing BField status: "
621 if(gainHandle->getNumberOfTags()!=2){
edm::LogError(
"SiStripGainFromCalibTree")<<
"NUMBER OF GAIN TAG IS EXPECTED TO BE 2\n";fflush(stdout);
exit(0);};
622 float newPreviousGain = gainHandle->getApvGain(APV->
APVId,gainHandle->getRange(APV->
DetId, 1),1);
626 float newPreviousGainTick = gainHandle->getApvGain(APV->
APVId,gainHandle->getRange(APV->
DetId, 0),1);
647 edm::LogInfo(
"SiStripGainFromCalibTree") <<
"Starting harvesting statistics" << std::endl;
655 if(stag.size()!=0 && stag[0]!=
'_') stag.insert(0,1,
'_');
689 edm::LogError(
"SiStripGainFromCalibTree") <<
"Harvesting: could not retrieve " << cvi.c_str()
690 <<
", statistics will not be summed!" << std::endl;
693 edm::LogInfo(
"SiStripGainFromCalibTree") <<
"Harvesting "
703 edm::LogError(
"SiStripGainFromCalibTree") <<
"Harvesting: could not retrieve " << cvpTIB.c_str()
704 <<
", statistics will not be summed!" << std::endl;
708 edm::LogError(
"SiStripGainFromCalibTree") <<
"Harvesting: could not retrieve " << cvpTOB.c_str()
709 <<
", statistics will not be summed!" << std::endl;
713 edm::LogError(
"SiStripGainFromCalibTree") <<
"Harvesting: could not retrieve " << cvpTIDP.c_str()
714 <<
", statistics will not be summed!" << std::endl;
718 edm::LogError(
"SiStripGainFromCalibTree") <<
"Harvesting: could not retrieve " << cvpTIDM.c_str()
719 <<
", statistics will not be summed!" << std::endl;
723 edm::LogError(
"SiStripGainFromCalibTree") <<
"Harvesting: could not retrieve " << cvpTECP1.c_str()
724 <<
", statistics will not be summed!" << std::endl;
728 edm::LogError(
"SiStripGainFromCalibTree") <<
"Harvesting: could not retrieve " << cvpTECP2.c_str()
729 <<
", statistics will not be summed!" << std::endl;
733 edm::LogError(
"SiStripGainFromCalibTree") <<
"Harvesting: could not retrieve " << cvpTECM1.c_str()
734 <<
", statistics will not be summed!" << std::endl;
738 edm::LogError(
"SiStripGainFromCalibTree") <<
"Harvesting: could not retrieve " << cvpTECM2.c_str()
739 <<
", statistics will not be summed!" << std::endl;
750 edm::LogInfo(
"SiStripGainFromCalibTree") <<
"Analyzing calibration tree" << std::endl;
762 edm::LogInfo(
"SiStripGainFromCalibTree") <<
"Saving summary into root file" << std::endl;
788 FitResults[0] = -0.5;
790 FitResults[2] = -0.5;
792 FitResults[4] = -0.5;
798 TF1* MyLandau =
new TF1(
"MyLandau",
"landau",LowRange, HighRange);
799 MyLandau->SetParameter(1,300);
800 InputHisto->Fit(MyLandau,
"0QR WW");
803 FitResults[0] = MyLandau->GetParameter(1);
804 FitResults[1] = MyLandau->GetParError(1);
805 FitResults[2] = MyLandau->GetParameter(2);
806 FitResults[3] = MyLandau->GetParError(2);
807 FitResults[4] = MyLandau->GetChisquare() / MyLandau->GetNDF();
808 FitResults[5] = MyLandau->GetParameter(0);
814 if(FitResults[0] <= 0 )
return false;
834 unsigned int FirstAmplitude=0;
835 for(
unsigned int i=0;
i<(*chargeoverpath).size();
i++){
836 FirstAmplitude+=(*nstrips)[
i];
837 int TI = (*trackindex)[
i];
871 bool Saturation =
false;
872 for(
unsigned int s=0;
s<(*nstrips)[
i];
s++){
873 int StripCharge = (*amplitude)[FirstAmplitude-(*nstrips)[
i]+
s];
877 if(StripCharge>1024){
880 }
else if(StripCharge>254){
884 Charge += StripCharge;
888 Charge = (*charge)[
i];
890 Charge = (*charge)[
i]/265.0;
895 double ClusterChargeOverPath = ( (double) Charge )/(*path)[
i] ;
897 if(
Validation) {ClusterChargeOverPath/=(*gainused)[
i];}
914 }
else if(APV->
Eta>0){
927 printf(
"Openning file %3i/%3i --> %s\n",
i+1, (
int)
VInputFiles.size(), (
char*)(
VInputFiles[
i].c_str())); fflush(stdout);
929 TString tree_path = TString::Format(
"gainCalibrationTree%s/tree",
m_calibrationMode.c_str());
930 TTree*
tree =
dynamic_cast<TTree*
> (tfile->Get(tree_path.Data()));
961 unsigned int nentries = tree->GetEntries();
962 printf(
"Number of Events = %i + %i = %i\n",
NEvent,nentries,(
NEvent+nentries));
963 printf(
"Progressing Bar :0%% 20%% 40%% 60%% 80%% 100%%\n");
964 printf(
"Looping on the Tree :");
965 int TreeStep = nentries/50;
if(TreeStep<=1)TreeStep=1;
966 for (
unsigned int ientry = 0; ientry < tree->GetEntries(); ientry++) {
967 if(ientry%TreeStep==0){printf(
".");fflush(stdout);}
968 tree->GetEntry(ientry);
979 double FitResults[6];
980 double MPVmean = 300;
985 edm::LogError(
"SiStripGainFromCalibTree") <<
"Harvesting: could not execute algoComputeMPVandGain method because "
987 <<
"Please check if input contains "
995 printf(
"Progressing Bar :0%% 20%% 40%% 60%% 80%% 100%%\n");
996 printf(
"Fitting Charge Distribution :");
999 if(I%TreeStep==0){printf(
".");fflush(stdout);}
1001 if(APV->
Bin<0) APV->
Bin = chvsidx->GetXaxis()->FindBin(APV->
Index);
1005 Proj = (TH1F*)(chvsidx->ProjectionY(
"",chvsidx->GetXaxis()->FindBin(APV->
Index),chvsidx->GetXaxis()->FindBin(APV->
Index),
"e"));
1010 int SecondAPVId = APV->
APVId;
1011 if(SecondAPVId%2==0){ SecondAPVId = SecondAPVId+1; }
else{ SecondAPVId = SecondAPVId-1; }
1013 if(APV2->
Bin<0) APV2->
Bin = chvsidx->GetXaxis()->FindBin(APV2->
Index);
1014 TH1F* Proj2 = (TH1F*)(chvsidx->ProjectionY(
"",APV2->
Bin,APV2->
Bin,
"e"));
1015 if(Proj2){Proj->Add(Proj2,1);
delete Proj2;}
1017 for(
unsigned int i=0;
i<16;
i++){
1018 __gnu_cxx::hash_map<unsigned int, stAPVGain*, __gnu_cxx::hash<unsigned int>,
isEqual >::iterator tmpit;
1023 if(APV2->
Bin<0) APV2->
Bin = chvsidx->GetXaxis()->FindBin(APV2->
Index);
1024 TH1F* Proj2 = (TH1F*)(chvsidx->ProjectionY(
"",APV2->
Bin,APV2->
Bin,
"e"));
1025 if(Proj2){Proj->Add(Proj2,1);
delete Proj2;}
1033 APV->
FitMPV = FitResults[0];
1039 APV->
NEntries = Proj->GetEntries();
1058 unsigned int tree_Index;
1059 unsigned int tree_Bin;
1060 unsigned int tree_DetId;
1061 unsigned char tree_APVId;
1062 unsigned char tree_SubDet;
1069 float tree_Thickness;
1071 float tree_FitMPVErr;
1072 float tree_FitWidth;
1073 float tree_FitWidthErr;
1074 float tree_FitChi2NDF;
1077 double tree_PrevGain;
1078 double tree_PrevGainTick;
1079 double tree_NEntries;
1083 MyTree = tfs->
make<TTree> (
"APVGain",
"APVGain");
1084 MyTree->Branch(
"Index" ,&tree_Index ,
"Index/i");
1085 MyTree->Branch(
"Bin" ,&tree_Bin ,
"Bin/i");
1086 MyTree->Branch(
"DetId" ,&tree_DetId ,
"DetId/i");
1087 MyTree->Branch(
"APVId" ,&tree_APVId ,
"APVId/b");
1088 MyTree->Branch(
"SubDet" ,&tree_SubDet ,
"SubDet/b");
1089 MyTree->Branch(
"x" ,&tree_x ,
"x/F");
1090 MyTree->Branch(
"y" ,&tree_y ,
"y/F");
1091 MyTree->Branch(
"z" ,&tree_z ,
"z/F");
1092 MyTree->Branch(
"Eta" ,&tree_Eta ,
"Eta/F");
1093 MyTree->Branch(
"R" ,&tree_R ,
"R/F");
1094 MyTree->Branch(
"Phi" ,&tree_Phi ,
"Phi/F");
1095 MyTree->Branch(
"Thickness" ,&tree_Thickness ,
"Thickness/F");
1096 MyTree->Branch(
"FitMPV" ,&tree_FitMPV ,
"FitMPV/F");
1097 MyTree->Branch(
"FitMPVErr" ,&tree_FitMPVErr ,
"FitMPVErr/F");
1098 MyTree->Branch(
"FitWidth" ,&tree_FitWidth ,
"FitWidth/F");
1099 MyTree->Branch(
"FitWidthErr" ,&tree_FitWidthErr,
"FitWidthErr/F");
1100 MyTree->Branch(
"FitChi2NDF" ,&tree_FitChi2NDF ,
"FitChi2NDF/F");
1101 MyTree->Branch(
"FitNorm" ,&tree_FitNorm ,
"FitNorm/F");
1102 MyTree->Branch(
"Gain" ,&tree_Gain ,
"Gain/D");
1103 MyTree->Branch(
"PrevGain" ,&tree_PrevGain ,
"PrevGain/D");
1104 MyTree->Branch(
"PrevGainTick" ,&tree_PrevGainTick,
"PrevGainTick/D");
1105 MyTree->Branch(
"NEntries" ,&tree_NEntries ,
"NEntries/D");
1106 MyTree->Branch(
"isMasked" ,&tree_isMasked ,
"isMasked/O");
1109 FILE* Gains = stdout;
1110 fprintf(Gains,
"NEvents = %i\n",
NEvent);
1111 fprintf(Gains,
"NTracks = %i\n",
NTrack);
1114 fprintf(Gains,
"Number of Pixel Dets = %lu\n",static_cast<unsigned long>(
NPixelDets));
1115 fprintf(Gains,
"Number of Strip APVs = %lu\n",static_cast<unsigned long>(
NStripAPVs));
1119 fprintf(Gains,
"NEvents = %i\n",
NEvent);
1120 fprintf(Gains,
"NTracks = %i\n",
NTrack);
1123 fprintf(Gains,
"Number of Strip APVs = %lu\n",static_cast<unsigned long>(
NStripAPVs));
1124 fprintf(Gains,
"Number of Pixel Dets = %lu\n",static_cast<unsigned long>(
NPixelDets));
1131 if(APV==
NULL)
continue;
1135 tree_Index = APV->
Index;
1137 tree_DetId = APV->
DetId;
1138 tree_APVId = APV->
APVId;
1139 tree_SubDet = APV->
SubDet;
1143 tree_Eta = APV->
Eta;
1145 tree_Phi = APV->
Phi;
1147 tree_FitMPV = APV->
FitMPV;
1151 tree_FitChi2NDF = APV->
FitChi2;
1153 tree_Gain = APV->
Gain;
1160 if(tree_DetId==402673324){
1161 printf(
"%i | %i : %f --> %f (%f)\n", tree_DetId, tree_APVId, tree_PrevGain, tree_Gain, tree_NEntries);
1167 if(Gains)fclose(Gains);
1178 edm::LogError(
"SiStripGainFromCalibTree") <<
"produceTagFilter -> Return false: could not retrieve the "
1180 <<
"Please check if input contains "
1190 <<
"produceTagFilter -> Return false: Statistics is too low : " << integral << endl;
1196 <<
"produceTagFilter -> Return false: ratio of GOOD/TOTAL is too low: " << (1.0 *
GOOD) / (
GOOD+
BAD) << endl;
1208 edm::LogWarning(
"SiStripGainFromCalibTree")<<
"getNewObject -> will not produce a paylaod because produceTagFilter returned false " << endl;
1214 std::vector<float>* theSiStripVector =
NULL;
1215 unsigned int PreviousDetId = 0;
1218 if(APV==
NULL){ printf(
"Bug\n");
continue; }
1219 if(APV->
SubDet<=2)
continue;
1220 if(APV->
DetId != PreviousDetId){
1221 if(theSiStripVector!=
NULL){
1223 if ( !obj->
put(PreviousDetId,range) ) printf(
"Bug to put detId = %i\n",PreviousDetId);
1225 theSiStripVector =
new std::vector<float>;
1226 PreviousDetId = APV->
DetId;
1228 theSiStripVector->push_back(APV->
Gain);
1230 if(theSiStripVector!=
NULL){
1232 if ( !obj->
put(PreviousDetId,range) ) printf(
"Bug to put detId = %i\n",PreviousDetId);
1246 TChain* t1 =
new TChain(
"SiStripCalib/APVGain");
1249 unsigned int tree_DetId;
1250 unsigned char tree_APVId;
1253 t1->SetBranchAddress(
"DetId" ,&tree_DetId );
1254 t1->SetBranchAddress(
"APVId" ,&tree_APVId );
1255 t1->SetBranchAddress(
"Gain" ,&tree_Gain );
1257 for (
unsigned int ientry = 0; ientry < t1->GetEntries(); ientry++) {
1258 t1->GetEntry(ientry);
edm::EDGetTokenT< std::vector< int > > trackindex_token_
std::vector< MonitorElement * > Charge_Vs_Index
T getParameter(std::string const &) const
EventNumber_t event() const
void swapBFieldMode(void)
virtual int nstrips() const =0
T getUntrackedParameter(std::string const &, T const &) const
std::vector< string > dqm_tag_
const std::vector< float > * trackp
unsigned int MinTrackHits
edm::EDGetTokenT< std::vector< double > > tracketa_token_
edm::EDGetTokenT< std::vector< unsigned char > > amplitude_token_
const std::vector< double > * chargeoverpath
edm::EDGetTokenT< std::vector< unsigned int > > rawid_token_
const std::vector< unsigned char > * amplitude
bool isBFieldConsistentWithMode(const edm::EventSetup &iSetup) const
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventIDconst &, edm::Timestampconst & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
SiStripApvGain * getNewObject() override
virtual int ncolumns() const =0
const std::vector< double > * localdirz
bool getByToken(EDGetToken token, Handle< PROD > &result) const
const std::vector< double > * trackchi2ndof
virtual void algoBeginRun(const edm::Run &run, const edm::EventSetup &iSetup) override
const std::vector< double > * localdirx
~SiStripGainFromCalibTree()
dispatcher processEvent(e, inputTag, standby)
#define DEFINE_FWK_MODULE(type)
unsigned int NClusterPixel
virtual void algoEndRun(const edm::Run &run, const edm::EventSetup &iSetup) override
const std::vector< unsigned int > * rawid
edm::EDGetTokenT< std::vector< bool > > overlapping_token_
double tagCondition_GoodFrac
SiStripGainFromCalibTree(const edm::ParameterSet &)
edm::Handle< T > connect(const T *&ptr, edm::EDGetTokenT< T > token, const edm::Event &evt)
virtual int nrows() const =0
const std::vector< int > * trackalgo
std::vector< MonitorElement * > Charge_Vs_PathlengthTOB
void storeOnTree(TFileService *tfs)
T * make(const Args &...args) const
make new ROOT object
const std::vector< float > * trackpt
std::vector< MonitorElement * > Charge_Vs_PathlengthTECM1
const std::vector< unsigned int > * trackhitsvalid
void MakeCalibrationMap()
std::vector< MonitorElement * > Charge_Vs_PathlengthTECM2
double MaxTrackChiOverNdf
edm::EDGetTokenT< std::vector< bool > > farfromedge_token_
bool put(const uint32_t &detID, Range input)
uint32_t rawId() const
get the raw id
edm::EDGetTokenT< std::vector< unsigned int > > trackhitsvalid_token_
T x() const
Cartesian x coordinate.
std::vector< stAPVGain * > APVsCollOrdered
__gnu_cxx::hash_map< unsigned int, stAPVGain *, __gnu_cxx::hash< unsigned int >, isEqual > APVsColl
edm::EDGetTokenT< std::vector< double > > path_token_
void algoComputeMPVandGain()
edm::EDGetTokenT< std::vector< int > > trackalgo_token_
edm::EDGetTokenT< std::vector< float > > trackp_token_
bool IsGoodLandauFit(double *FitResults)
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
virtual void algoBeginJob(const edm::EventSetup &iSetup) override
std::pair< ContainerIterator, ContainerIterator > Range
edm::EDGetTokenT< std::vector< bool > > TrigTech_token_
edm::EDGetTokenT< std::vector< double > > chargeoverpath_token_
const std::complex< double > I
const std::vector< double > * gainused
std::vector< MonitorElement * > Charge_Vs_PathlengthTECP1
edm::EDGetTokenT< std::vector< double > > localdirz_token_
const std::vector< unsigned short > * firststrip
std::vector< MonitorElement * > Charge_Vs_PathlengthTIDM
const std::vector< double > * localdiry
edm::EDGetTokenT< std::vector< unsigned int > > charge_token_
int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
Integral< F, X >::type integral(const F &f)
vector< string > VInputFiles
virtual void algoEndJob() override
edm::EDGetTokenT< std::vector< unsigned short > > nstrips_token_
std::vector< MonitorElement * > Charge_Vs_PathlengthTECP2
const std::vector< int > * trackindex
int statCollectionFromMode(const char *tag) const
std::vector< MonitorElement * > Charge_Vs_PathlengthTIB
edm::EDGetTokenT< std::vector< unsigned short > > firststrip_token_
virtual void algoAnalyze(const edm::Event &, const edm::EventSetup &) override
edm::EDGetTokenT< std::vector< float > > trackpt_token_
T const * product() const
const std::vector< bool > * overlapping
const std::vector< bool > * saturation
bool merge(LuminosityBlockRange &lh, LuminosityBlockRange &rh)
void getPeakOfLandau(TH1 *InputHisto, double *FitResults, double LowRange=50, double HighRange=5400)
T const * product() const
void algoAnalyzeTheTree()
const std::vector< bool > * farfromedge
const std::vector< bool > * TrigTech
void setDoStore(const bool doStore)
When set to false the payload will not be written to the db.
TH2F * getTH2F(std::string name, std::string process, std::string rootfolder, DQMStore *dbe_, bool verb, bool clone)
double tagCondition_NClusters
edm::EDGetTokenT< std::vector< double > > localdirx_token_
edm::EDGetTokenT< std::vector< bool > > saturation_token_
edm::EDGetTokenT< std::vector< double > > trackchi2ndof_token_
std::vector< MonitorElement * > Charge_Vs_PathlengthTIDP
edm::EDGetTokenT< std::vector< double > > localdiry_token_
volatile std::atomic< bool > shutdown_flag false
const std::vector< unsigned int > * charge
const std::vector< double > * path
const std::vector< double > * trackphi
const std::vector< unsigned short > * nstrips
edm::EDGetTokenT< std::vector< double > > gainused_token_
void bookDQMHistos(const char *dqm_dir, const char *tag)
edm::EDGetTokenT< std::vector< double > > trackphi_token_
const std::vector< double > * tracketa
unsigned int NClusterStrip
void merge(TH2 *A, TH2 *B)